<template>
  <div>
    <div><h1>我的拼团</h1></div>
    <div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="groupId" label="ID" width="50" />
        <el-table-column prop="joinId" label="活动Id" width="50" />
        <el-table-column prop="teamHeader" label="团长电话" width="100" />
        <el-table-column prop="teamLimit" label="拼团人数" width="100" />
        <el-table-column prop="joinNum" label="参加人数" width="100" />
        <el-table-column prop="beginTime" label="开始时间" width="240" />
        <el-table-column prop="endTime" label="截止时间" width="240" />
        <el-table-column prop="groupStatus" label="拼团状态" width="100" />
        <el-table-column prop="createBy" label="创建人电话" width="100" />
        <el-table-column prop="createTime" label="创建时间" width="100" />
        <el-table-column label="操作" width="350">
          <template #default="scope"> </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="margin-top: 20px">
      <div class="demo-pagination-block">
        <el-pagination
          v-model:current-page="searchForm.pageNum"
          v-model:page-size="searchForm.pageSize"
          :page-sizes="[2, 4, 6, 8]"
          :background="true"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import { getRcordsList } from "../api/api";
import { ElMessage } from "element-plus";

const tableData = ref([]);
const total = ref(0);

const searchForm = ref({
  pageNum: 1,
  pageSize: 2,
  keyWord: null,
});

//分页
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  loadList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  loadList();
};

//查询列表
const loadList = () => {
  getRcordsList(searchForm.value).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};

//初始化数据
onMounted(() => {
  loadList();
});
</script>

<style scoped></style>
